#include <iostream>
using namespace std;

int maxsum(int array[], int n, int& l, int& h)
{
	int max_sofar = 0;
	int max_endhere = 0;
	l = h = 0;
	int t;
	for(int i = 0; i < n; i++)
	{
		if(max_endhere > 0)
			max_endhere += array[i];
		else
		{
			max_endhere = array[i];
			t = i;
		}
		if(max_endhere > max_sofar)
		{
			max_sofar = max_endhere;
			l = t;
			h = i;
		}
	}
	return max_sofar;
}


int main()
{
	int l, h;
	int array1[] = {31,-41,59,26,-53,58,97,-93,-23,84};
	cout << maxsum(array1,10,l,h) << " " << l << " " << h << endl;
	int array2[] = {-1,-2,-3,-4,-5,-6,-7,-8,-9,-10};
	cout << maxsum(array2,10,l,h) << " " << l << " " << h << endl;
	int array3[] = {1,2,3,4,5,6,7,8,9,10};
	cout << maxsum(array3,10,l,h) << " " << l << " " << h << endl;
	return 0;
}
